#include "graphicsobject.h"
#include "animation.h"
#include "texture.h"
#include "../physics/collisionshapes.h"
#include <QUndoStack>

GraphicsObject::GraphicsObject(QObject *parent)
    : AbstractObject(parent)
{
    m_csUndoStack = new QUndoStack(this);
}

void GraphicsObject::addAnimation(QPointer<Animation> anim)
{
    if(m_anims.contains(anim)) return;
    m_anims.append(anim);
    emit animationAdded(anim);
}

void GraphicsObject::removeAnimation(QPointer<Animation> anim)
{
    if(!m_anims.contains(anim)) return;
    m_anims.removeOne(anim);
    emit animationRemoved(anim);
}

const GraphicsObject::AnimationSet &GraphicsObject::animations() const
{
    return m_anims;
}

QPointer<Animation> GraphicsObject::animationByID(const QString &id)
{
    QPointer<Animation> result;

    foreach(QPointer<Animation> anim, m_anims)
    {
        if(anim->id() == id)
        {
            result = anim;
            break;
        }
    }

    return result;
}

QPointer<Texture> GraphicsObject::texture() const
{
    return m_texture;
}

bool GraphicsObject::hasAnimations() const
{
    return m_anims.size() > 0;
}

bool GraphicsObject::hasTexture() const
{
    return m_texture != 0;
}

const QList<QPointer<CollisionShape> > &GraphicsObject::collisionShapes() const
{
    return m_collisionShapes;
}

QList<QPointer<CollisionShape> > &GraphicsObject::collisionShapes()
{
    return m_collisionShapes;
}

QPointer<QUndoStack> GraphicsObject::csUndoStack() const
{
    return m_csUndoStack;
}

void GraphicsObject::setTexture(QPointer<Texture> texture)
{
    if(m_texture == texture) return;
    m_texture = texture;
    emit textureChanged(texture);
}
